package cn.edu.xjtu.nbrash.xbarsuite.zxingdemo;

import java.util.HashMap;
import java.util.Map;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import cn.edu.xjtu.nbrash.xbarsuite.RashIntents;
import cn.edu.xjtu.nbrash.xbarsuite.result.RashResultActivity;

public class RashResultDisplayTestActivity extends ListActivity {

	private String[] items;
	private Map<String, String> results;

	private static final String rText = "this is a string!";
	private static final String rWifi = "WIFI:T:WPA;P:1234567890;S:xjtuse;";
	private static final String rContact = "MECARD:N:张某;ORG:哈哈哈;TIL:呵呵呵;TEL:12345678901;TEL:12345689701;URL:http://www.baidu.com;ADR:没钱买房;NOTE:备注信息;";

	private void init() {
		results = new HashMap<>();

		results.put("Text", rText);
		results.put("Wifi", rWifi);
		results.put("Contact", rContact);

		items = results.keySet().toArray(new String[0]);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		init();
		setListAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, items));
	}

	public void onListItemClick(ListView parent, View v, int position, long id) {
		String strResult = results.get(items[position]);
		Intent intent = new Intent(this, RashResultActivity.class);
		intent.putExtra(RashIntents.Result.EXTRA_RESULT, strResult);
		startActivity(intent);
	}
}
